package com.tlvip.tlvipweb.config;

import com.tlvip.tlvipweb.filter.ReqResFilter0;
import com.tlvip.tlvipweb.filter.ReqResFilter1;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>description：测试过滤器执行顺序</p>
 * <p>copyright： copyright(C)2016-2099</p>
 * <p>Life is short,we need passion</p>
 * <p>Summary： </p>
 * <p>instructions： </p>
 * Date 3/7/21</p>
 * Author mac
 *
 * @version 1.0
 */
@Configuration
public class WebConfig {
    @Bean
    public FilterRegistrationBean reqResFilter1() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        ReqResFilter1 reqResFilter1 = new ReqResFilter1();

        filterRegistrationBean.setFilter(reqResFilter1);
//        filterRegistrationBean.addUrlPatterns("*.json");//配置过滤规则
        filterRegistrationBean.addUrlPatterns("*");//配置过滤规则
        filterRegistrationBean.addInitParameter("name", "hahahhhaa");//设置init参数
        filterRegistrationBean.setName("reqResFilter1");//设置过滤器名称
        filterRegistrationBean.setOrder(2);//执行次序

        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean reqResFilter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        ReqResFilter0 reqResFilter = new ReqResFilter0();

        filterRegistrationBean.setFilter(reqResFilter);

        //配置多个过滤规则
//        List<String> urls = new ArrayList<>();
//        urls.add("/order/*");
//        urls.add("/user/*");
//        filterRegistrationBean.setUrlPatterns(urls);

//        filterRegistrationBean.addUrlPatterns("*.json");//配置过滤规则
        filterRegistrationBean.addUrlPatterns("*");//配置过滤规则
        filterRegistrationBean.setName("reqResFilter");//设置过滤器名称
        filterRegistrationBean.setOrder(1);//执行次序

        return filterRegistrationBean;
    }
}
